import { get, post, fileUploadPost } from '@/utils/request'

interface UploadProgressCallback {
    (percentCompleted: number): void;
}

export const fileUpload = async (
    data: any,
    onUploadProgress: UploadProgressCallback,
    controller: AbortController,
): Promise<any> => {
    try {
        const response = await fileUploadPost<any>('/file/upload', data, onUploadProgress, {
            signal: controller.signal,
        });
        return response;
    } catch (error) {
    }
};

export const filePage = async (data: any) => {
    try {
        const response = await post<any>('/file/page', data);
        return response;
    } catch (error) {
    }
};

export const fileDelete = async (data: any) => {
    try {
        const response = await post<any>('/file/delete', data);
        return response;
    } catch (error) {
    }
};


export interface FileData {
    id: number,
    name: string,
    size: number,
    createTime: string,
    previewUrl: string,
    url: string,
}
export interface QueryParams {
    pageNum: number,
    pageSize: number,
    name: string,
    startEndData: string,
    startDate: string,
    endDate: string,
}

export interface FileUploadData {
    file: File | null,
    name: string,
    imageSrc: string,
    previewSrcList: string[],
    size: number,
    process: number,
    abortController: AbortController | null,
    // 后台处理结果 0 正在处理; 1 成功; 2 失败
    status: number,
    // 后台处理失败信息
    failMsg: string,
}
export interface FileDataSend {
    file: File | null,
    name: string,
    size: number,
}